<template>
	<view class="margin-top bg-white padding-lr">
		<u-form :model="info" ref="form" label-width="auto">
			<u-form-item label="日期" prop="date" required>
				<cmp-picker mode="time" v-model="info.date"></cmp-picker>
			</u-form-item>
			<u-form-item label="类型" prop="type" required>
				<cmp-picker v-model="info.type" :range="typeOptions" range-key="label" range-value="value"></cmp-picker>
			</u-form-item>
			<view class="padding-tb"><u-button type="primary" @click="save">保存</u-button></view>
		</u-form>
	</view>
</template>

<script>
export default {
	onLoad: function(option) {
		if (option.info) {
			this.info = JSON.parse(decodeURIComponent(option.info));
		}
	},
	onReady: function() {
		this.$refs.form.setRules(this.rules);
	},
	data() {
		return {
			show: false, // 显示选项
			info: {
				id: '',
				date: '',
				type: '',
			},
			rules: {
				date: [{ required: true, message: '必填', trigger: ['change', 'blur'] }],
				type: [{ required: true, message: '必填', trigger: ['change', 'blur'] }]
			},
			typeOptions: [
				{
					label: '放假',
					value: 'HOLIDAY'
				},
				{
					label: '调班',
					value: 'WORKDAY'
				}
			]
		};
	},
	methods: {
		// 保存用户
		save: function() {
			this.$refs['form'].validate(valid => {
				if (valid) {
					this.$request.post(
						'/admin/sys/holiday/save',
						this.info,
						res => {
							this.$utils.showModal('保存成功！', () => {
								uni.navigateBack({
									delta: 1
								});
							});
						},
						false,
						true,
						true
					);
				}
			});
		}
	}
};
</script>

<style lang="scss" scoped></style>
